public class TestDemo3 {
    public static void main(String[] args) {
        String str = addBinary("1","111");
        System.out.println(str);
    }
    public static String addBinary(String a, String b) {
        int left = a.length()-1;
        int right = a.length()-1;
        int ret = 0;
        StringBuilder sb = new StringBuilder();
        while(left>=0 && right>=0){
            int a1 = a.charAt(left)-'0';
            int b1 = b.charAt(right)-'0';
            int sum = (ret+a1+b1)%2;
            if(ret+a1+b1 >1){
                ret = 1;
            }else{
                ret = 0;
            }
            sb.append(sum);
            left--;
            right--;
        }
        while(left>=0){
            int a1 = a.charAt(left)-'0';
            int sum = (a1 + ret) %2;
            if(a1+ret > 1) ret = 1;
            else ret = 0;
            sb.append(sum);
            left--;
        }
        while(right>=0){
            int a1 = b.charAt(right)-'0';
            int sum = (a1 + ret) %2;
            if(a1+ret > 1) ret = 1;
            else ret = 0;
            sb.append(sum);
            right--;
        }
        if(ret != 0){
            sb.append(ret);
        }
        return sb.reverse().toString();
    }
}
